package org.cmcc.pcap.jpcap.capture;


import org.cmcc.pcap.jpcap.tcp.TcpProtocolHandler;
import org.cmcc.pcap.jpcap.tcp.http.HttpHandler;
import org.cmcc.pcap.jpcap.tcp.https.HttpsHandler;
import org.cmcc.pcap.jpcap.tcp.tcp.TcpHandler;
import org.cmcc.pcap.jpcap.udp.UdpHandler;
import org.cmcc.pcap.jpcap.udp.UdpProtocolHandler;

/**
 * @Auther: zdw
 * @Date: 2019-10-14 10:46
 * @Description:
 */
public class HandlerManager {
    //传入的handler参数
	public static TcpProtocolHandler tcpHandler;
	public static TcpProtocolHandler httpHandler;
	public static TcpProtocolHandler httpsHandler;
	public static UdpProtocolHandler udpHandler;

    /**
     * 获取handler的方法
     * @param type
     * @return
     * @throws IllegalAccessException
     * @throws InstantiationException
     */
    public static synchronized TcpProtocolHandler getHandler(String type) throws IllegalAccessException, InstantiationException {
		if ("tcp".equals(type)) {
			if (tcpHandler == null) {
				tcpHandler = new TcpHandler();
			}

			return tcpHandler;
		} else if ("http".equals(type)) {
			if (httpHandler == null) {
				httpHandler = new HttpHandler();
			}

			return httpHandler;
		} else if ("https".equals(type)) {
			if (httpsHandler == null) {
				httpsHandler = new HttpsHandler();
			}

			return httpsHandler;
		} else {
			return null;
		}
    }

    public static synchronized UdpProtocolHandler getUdpHandler() throws IllegalAccessException, InstantiationException {
		if (udpHandler == null) {
			udpHandler = new UdpHandler();
		}

		return udpHandler;
    }


}
